package com.win.controller;

import com.win.pojo.Product;
import com.win.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
public class ProductController {

    @Autowired
    private ProductService productService;

    @RequestMapping("/product/{id}")
    public Product product(@PathVariable("id") Long id){
        log.info("hello product!");
        Product product = productService.getProductById(id);
        //测试异常熔断策略
//        int i = 1/0;

        //测试慢调用比例策略
//        try {
//            TimeUnit.SECONDS.sleep(2);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
        return product;
    }
}